package com.luoqiz.project.qq.server.threads;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.Socket;

import com.luoqiz.project.qq.server.ServerAppMain;

public class SingleChatThread extends Thread {

	private Socket socket;

	// private ServerMain serverMain;

	public SingleChatThread() {
	}

	public SingleChatThread(Socket socket) {
		this.socket = socket;
		
	}

	public void run() {
		ServerAppMain.sessionMap.put((socket.getRemoteSocketAddress()+"").substring(1), socket);
		System.out.println("地址" + socket.getRemoteSocketAddress());
		BufferedInputStream bin = null;
		try {
			bin = new BufferedInputStream(socket.getInputStream());
			byte[] b = new byte[1024];
			int len = -1;
			while ((len = bin.read(b)) != -1) {
				String s = new String(b, 0, len);
				System.out.println(s);
				ServerAppMain.msgContentJta.append("地址" + socket.getRemoteSocketAddress() + "--" + s + "\r\n");
			}
			ServerAppMain.sessionMap.remove(socket.getRemoteSocketAddress()+"");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
